<template>

    <!-- 所有的内容要被根节点包含起来 -->
    <div id="">
        <!--顶部滑动条区域-->
        <div id="slider" class="mui-slider">
            <div id="sliderSegmentedControl"
                 class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <a :class="['mui-control-item', item.id == 0 ? 'mui-active' : '']" v-for="item in cates"
                       :key="item.id">
                        {{ item.title }}
                    </a>
                </div>
            </div>
        </div>

        <div class="Lazyload">
            <ul class="Lazyload-ul">
                <router-link :to="'/home/photoinfo/' + item.id" class="Lazyload-li" v-for="item in list" :key="item.id" tag="li">
                    <img class="Lazyload-li-img" v-lazy="item.img">
                    <div class="info">
                        <p class="info-title">{{ item.abstract }}</p>
                    </div>
                </router-link>
            </ul>
        </div>

    </div>


</template>

<script type="text/javascript">

    // 导入mui.js
    import mui from '../../libs/mui/js/mui.js'

    export default {
        data: function () {
            return {
                cates: [],      // 所有分类的列表
                list: []        // 图片数据
            }
        },
        // mounted() 当组件被渲染好并放到页面中的后, 会执行这个钩子函数
        mounted() {
            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            });
        },
        created() {
            this.getAllCategory()
            this.getImgGes()
        },
        // 执行的方法
        methods: {
            getAllCategory() {
                this.$http.get('./src/FalseData/getImgCategory.json').then(res => {
                    if (res.body.status === 0) {
                        res.body.message.unshift({title: "全部", id: 0});
                        this.cates = res.body.message;
                    }
                })
            },

            getImgGes() {
                this.$http.get('./src/FalseData/getImgGes.json').then(res => {
                    if (res.body.status === 0) {
                        this.list = res.body.message;
                    }
                })
            }
        }
    }

</script>

<style lang="scss" scoped>
    * {
        margin: 0;
        padding: 0;
        touch-action: pan-y;
    }

    .Lazyload-ul {
        list-style: none;
        margin: 0;
        padding: 10px;
        padding-bottom: 0;
        li {
            background-color: #ccc;
            text-align: center;
            margin-bottom: 10px;
            box-shadow: 0 0 9px #999;
            position: relative;
            .Lazyload-li-img {
                width: 100%;
                vertical-align: middle;
                border-radius: 5px;
            }
            img[lazy="loading"] {
                width: 40px;
                height: 300px;
                margin: auto;
            }

            .info {
                width: 100%;
                color: white;
                text-align: left;
                position: absolute;
                bottom: 0;
                background-color: rgba(0, 0, 0, 0.4);
                border-radius: 5px;
                .info-title {
                    font-size: 13px;
                    padding: 5px;
                    line-height: 1.5;
                    text-align: justify;
                    color: #ffffff;

                    overflow : hidden;
                    text-overflow: ellipsis;
                    display: -webkit-box;
                    -webkit-line-clamp: 3;
                    -webkit-box-orient: vertical;
                }
                .info-body {
                    font-size: 13px;
                }
            }
        }
    }
</style>
